﻿@using MvcFileUploader.HtmlHelper
@using MvcFileUploader.Models
@{
    ViewBag.Title = "Demo";

    var showingInline = Model != null && Model == true;
    
    //option for inline view only
    var ui = "jquery".Equals(Request.Params["ui"]) ? UploadUI.JQueryUI : UploadUI.Bootstrap;
    var toggleUi = ui == UploadUI.Bootstrap ? "jquery" : "bootstrap";
    
    //setting layout based on ui
    Layout = "~/Views/Shared/" + (ui == UploadUI.Bootstrap ? "_MvcFileUploaderLayout.cshtml" : "_MvcFileUploaderLayout_jui.cshtml");
}

@if (!showingInline)
{
    <div class="well">
        <legend>Upload Dialog</legend>
        <p class="help-block">jpg/png size max 30 MB, single file upload</p>
        @(
        Html.MvcFileUpload()
        .UploadAt(Url.Action("UploadFile"))
        .WithFileTypes(@"/(\.|\/)(jpe?g|png)$/i")
        .WithMaxFileSize(10000000)        
        .AddFormField("entityId", "1234")        
        .RenderPopup("Upload", "#dlgFileUpload", new {@class="btn btn-large btn-primary"})
        )
    </div>


    <div class="well">
        <legend>Upload Dialog with return url on closing</legend>        
        <p class="help-block">jpg/png size max 30 MB</p>
        @(
        Html.MvcFileUpload()
        .UploadAt(Url.Action("UploadFile"))        
        .ReturnAt("/MvcUploaderTest/Demo?inline=True")
        .WithFileTypes(@"/(\.|\/)(jpe?g|png)$/i")
        .WithMaxFileSize(10000000) 
        .RenderPopup("Upload Button Label", "#dlgFileUpload", new {@class="btn btn-large btn-primary"})
        )
    </div>
    
    <!-- file upload modal dialog -->
    <div class="modal fade" id="dlgFileUpload" tabindex="-1" role="dialog" aria-hidden="true">
  
    </div><!-- /.modal -->           
    
     
}


@if(showingInline)
{
    <div class="well">
        <legend>Upload Inline</legend>
        <p class="help-block">jpg/png size max 30 MB</p>
        @(
        Html.MvcFileUpload()
        .UploadAt(Url.Action("UploadFile"))
        .UIStyle(ui)
        .WithFileTypes(@"/(\.|\/)(jpe?g|png)$/i")
        .WithMaxFileSize(10000000)
        .AddFormField("entityId", "1234")
        .RenderInline("_MvcFileupload")
        )
        
    </div>
    
    <div class="well">
        <legend>Another inline uploader in same page</legend>
        <p class="help-block">jpg/png size max 30 MB, max number of files 2, image preview disabled</p>
        <p class="help-block">note: do not set thumbnailUrl in returned json from server side controller in case image preview is disabled, in this demo it is being set, so tumbnail is shown after upload.</p>
        @(
        Html.MvcFileUpload() 
        .UploadAt(Url.Action("UploadFile"))
        .WithFileTypes(@"/(\.|\/)(jpe?g|png)$/i")
        .WithMaxFileSize(10000000)
        .MaxNumberOfFiles(2)
        .DisableImagePreview()
        .ExcludeSharedScript()  //this should be called as this page contains another inline widget which loaded shared scripts
        .RenderInline("_MvcFileupload")
        )
    </div>       
    
    <div class="well">
        <legend>Server side error generation</legend>
        <p class="help-block">Randomly generates error file size or entityId error from server side controller code. Any file type.</p>
        @(
        Html.MvcFileUpload() 
        .UploadAt(Url.Action("UploadFile"))
        .WithMaxFileSize(10000000) 
        .AddFormField("entityId", "13")
        .ExcludeSharedScript()  //this should be called as this page contains another inline widget which loaded shared scripts
        .RenderInline("_MvcFileupload")
        )
    </div>
    
    <p>
        @Html.ActionLink("Show "+toggleUi+" ui", "Demo", new {inline=true, ui=toggleUi}, new {@class="btn btn-info"})
    </p>
}


@Html.ActionLink(showingInline?"Show modal dialog demo":"Show inline demo", "Demo", new {inline=!showingInline}, new {@class="btn btn-info"})
